package cn.edu.swu.bc.servlet;

import cn.edu.swu.bc.filter.AuthFilter;
import cn.edu.swu.bc.utils.DBUtils;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Writer;
import java.sql.SQLException;

public class FanHimServlet  extends HttpServlet {

    private static final long serialVersionUID = 1191212124340L;
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        this.doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        int fid=Integer.parseInt(request.getParameter("id"));
        int id=(Integer) request.getSession().getAttribute(AuthFilter.USER_ID);
        String  sql="insert into `friends` values ("+id+","+fid+");";
        Writer writer = response.getWriter();
        System.out.println(sql);
        try {
            DBUtils.insert(sql);
            writer.write("关注成功");
        } catch (SQLException throwables) {
            writer.write("关注失败，请勿重复关注");
        }
    }
}
